package com.zwps.common.api.validator;

import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;
import cn.hutool.core.util.PhoneUtil;
import cn.hutool.core.util.StrUtil;

/**
 * 手机号码校验
 * 
 * @ClassName: PhoneValidator
 * @Description:
 * @author lyh
 * @date 2023年5月23日 下午3:17:14
 *
 */
public class PhoneValidator implements ConstraintValidator<Phone, CharSequence> {

    @Override
    public void initialize(Phone phone) {
    }

    @Override
    public boolean isValid(CharSequence value, ConstraintValidatorContext context) {
        if (StrUtil.isEmpty(value)) {
            return true;
        }
        return PhoneUtil.isPhone(value);
    }

}
